import { message } from 'ant-design-vue'
import axios from 'axios'

const service = axios.create({
  baseURL: '/api',
  timeout: 10000
})

service.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  (response) => {
    console.log(response)
    return response.data
  },
  (error) => {
    if (error.response.status === 400) {
      message.error(error.response.data.msg)
    }
    return Promise.reject(error)
  }
)

export default service
